package com.apache.rpc.server.impl;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import com.apache.cache.util.Validator;
import com.apache.method.SystemRunnable;

/**
 * 
 * description:  
 * @author Hou Dayu 创建时间：2014-11-4  
 * @Copyright(c)2014:
 */
public class ProtocolEncryptionServer extends SystemRunnable {

	private ServerSocket server = null;
	private Socket socket = null;

	private String portStr;

	public ProtocolEncryptionServer(String portStr) {
		this.portStr = portStr;
	}

	@Override
	public void run() {
		String port = Validator.getDefaultStr(portStr, "9002");
		try {
			server = new ServerSocket(Integer.parseInt(port));
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		while (true) {
			try {
				socket = server.accept();
				new Thread(new ProtocolSocketEncryptionServer(socket), "socket 服务线程").start();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
